package com.example.xzc.cainiaoshangcheng.ViewHolder;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

/**
 * @projectName: CaiNiaoShangCheng    ---------> 项目名称
 * @description: --------->描述
 * @author: xzc                              --------->作者
 * @date: 2017-03-13    --------->日期
 * @time: 22:30               --------->时间
 */

public class BaseViewHolder extends RecyclerView.ViewHolder {

    private SparseArray<View> views;

    public BaseViewHolder(View itemView) {
        super(itemView);

        views = new SparseArray<>();
    }

    public TextView findTextView(int id){
        return findView(id);
    }

    public CheckBox findCheckBox(int id){
        return findView(id);
    }

    private <T extends View> T findView(int id){
        View view = views.get(id);
        if(view == null){
            view = itemView.findViewById(id);
            views.put(id,view);
        }
        return (T) view;
    }

}
